<template>
	<view style="flex-direction: column; flex: 1;">

		<block v-for="(item,index) in productList" :key="index">

			<view class="">
				<view style="flex-direction: column; flex: 1;">
					<view style="height: 750upx;">
						<image :src="item.img" mode="" style="width: 100%; height: 100%;"></image>
					</view>
					<view style="padding-top: 30upx; padding-left: 20upx; padding-right: 20upx; font-size: 30upx; font-weight: bold;">
						{{item.title}}</view>
					<view style="padding: 20upx;">
						<view>
							<view>
								¥{{item.price}}
							</view>
							<view style="padding-left: 20upx;">
								{{item.seller_count}}
							</view>
						</view>
						<view style="flex: 1; justify-content: flex-end;">
							<view>
								<button type="warn" size="mini">购买</button>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view style="background-color: #8F8F94; height: 20upx;"></view>
		</block>

	</view>
</template>

<script>
	var self;
	export default {
		 data() {
		  return {
			productList: [],
      }
		},
		onLoad() {
			self = this;
			let page = 1;
			let url = `https://api.beidian.com/mroute.html?method=beidian.h5.shop.product.list&page=${page}&shop_id=682731`;
      console.log(url)
      // 指定允许其他域名访问
//       res.header("Access-Control-Allow-Origin", "*");
//     res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
//     res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");

			uni.request({
				url: url,
//         header:{
//           // 'content-type': 'application/json',
//           // 'Access-Control-Allow-Origin':'*',
// //           'Access-Control-Allow-Methods':'PUT,POST,GET,DELETE,OPTIONS',
// //           'Access-Control-Allow-Headers':'X-Requested-With,Content-Type'
//         },
				success(res) {
           console.log(res)
					const data = res.data;
					self.productList = data.shop_products;
				},
        error(e){
          console.log(JSON.stringify(e))
        }
			})
		}
	}
</script>

<style>
	view {

		/* 			margin: 10upx;
		border: #8F8F94 solid 1upx; */

		display: flex;
		flex-direction: row;

		font-size: 28upx;
	}
</style>
